package liudan.archetype.servlet;


import liudan.archetype.xmlutil.StrutsXmlParser;
import liudan.archetype.xmlutil.XmlBean;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.util.Map;

/**
 * Description:
 * Title
 * Copyright: Copyright (c) 2017
 * User: liudan
 * Created on 2017/2/18 15:36
 */
public class StrutsListen implements ServletContextListener {

    public void contextInitialized(ServletContextEvent servletContextEvent) {
        try {
            ServletContext servletContext = servletContextEvent.getServletContext();
            String xmlPath = this.getClass().getClassLoader().getResource("struts-config.xml").getPath();
            Map<String, XmlBean> map = StrutsXmlParser.parser(xmlPath);
            servletContext.setAttribute("struts-config", map);
            System.out.println("系统初始化完成................");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("系统初始化异常" + e);
        }
    }

    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        System.out.println("提示：系统已经注销");
    }
}
